package com.liuya.common.listener;

import com.liuya.common.SpringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class ServerListerner implements ServletContextListener {
    protected final Logger logger = LogManager.getLogger(this.getClass());

    public void contextDestroyed(ServletContextEvent contextEvent) {
    }

    public void contextInitialized(ServletContextEvent contextEvent) {
        WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
        SpringUtils.WEB_CONTEXT = context;

        //在系统启动时缓存所有用户数据到redis
//        context.getBean(SysUserProvider.class).init();
//        SysDicProvider sysDicProvider = context.getBean(SysDicProvider.class);
//        sysDicProvider.getAllDic();
        logger.info("=================================");
        logger.info("common监听系统[{}]启动完成!!!", contextEvent.getServletContext().getServletContextName());
        logger.info("=================================");
    }
}
